﻿using Blog1._0.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Until;
using Blog1._0.Model;

namespace Blog1._0.Service
{
    /// <summary>
    /// 【QQ授权】逻辑层
    /// </summary>
    public class QQUserService : Repository
    {
        /// <summary>
        /// 查询QQ用户信息
        /// </summary>
        /// <param name="openid"></param>
        /// <returns></returns>
        public IQueryable<Guo_QQUser> GetQQUserInfo(string openid)
        {
            var db = this.Base();
            var query = db.IQueryable<Guo_QQUser>(t => t.OpenId == openid);
            return query != null ? query : null;
        }

        /// <summary>
        /// 插入Email
        /// </summary>
        /// <param name="openid"></param>
        /// <param name="email"></param>
        /// <returns></returns>
        public bool InsertEmail(string openid, string email)
        {
            var db = this.Base();
            var user = db.FindEntity<Guo_QQUser>(t => t.OpenId == openid);
            user.Email = email;
            db.Update(user);

            return db.Commit() > 0 ? true : false;
        }

        /// <summary>
        /// 返回被回复者的信息
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public Guo_QQUser GetEmails(int Id)
        {
            var db = this.Base();
            var query = db.FindEntity<Guo_QQUser>(t => t.Id == Id);
            return query;
        }
    }
}
